﻿using System;
using System.Data;
using Model.Data;
using Model;
using DataAccess;
using BusinessLogic.BusinessRules;

namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// CommentFactory 的摘要说明。
    /// </summary>
    public class CommentFactory : BaseFactory
    {
        public CommentFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public CommentFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }
        public Comment NewInstance()
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            objComment.NewDataSet();
            objComment.SelectRow(0);
            return objComment;
        }

        public int DeleteComment(int intID)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            return l_Access.Delete(intID);
        }
        public int DeleteCommentWhere(string where)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            return l_Access.DeleteWhere(where);
        }
        public int UpdateSort(int intSectionID)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            return l_Access.UpdateSort(intSectionID);

        }
        public int QueryByCompletionSql(string Sql)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            DataSet l_ds = new CommentData();
            if (l_Access.QueryByQuerySql(ref l_ds, Sql) < 1)
            {
                return 0;
            }
            objComment.SetDataSet(l_ds);
            objComment.SelectRow(0);
            return objComment.Data.Comment.Rows.Count;
        }
        public Comment CreatorBySql(string Sql)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            DataSet l_ds = new CommentData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objComment.SetDataSet(l_ds);
            objComment.SelectRow(0);
            return objComment;
        }

        public DataSet CreatorBySqlDataSet(string Sql)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            DataSet objDataSet = new DataSet();
            l_Access.QueryByQuerySql(ref objDataSet, Sql);
            return objDataSet;
        }

        public Comment CreatorByFullSql(string Sql)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            DataSet l_ds = new CommentData();
            if (l_Access.QueryByQuerySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objComment.SetDataSet(l_ds);
            objComment.SelectRow(0);
            return objComment;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="intCommentID"></param>
        /// <returns></returns>
        public Comment Creator(int intCommentID)
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            DataSet l_ds = new CommentData();
            if (l_Access.QueryByID(ref l_ds, intCommentID) < 1)
            {
                return null;
            }
            objComment.SetDataSet(l_ds);
            objComment.SelectRow(0);
            return objComment;
        }

        public Comment Creator()
        {
            CommentAccess l_Access = new CommentAccess(m_Manager);
            Comment objComment = new Comment(this.m_Manager, l_Access);
            DataSet l_ds = new CommentData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;

            }
            objComment.SetDataSet(l_ds);
            objComment.SelectRow(0);
            return objComment;
        }

    }
}
